package cate.game.play.proce.stat;

import java.util.HashMap;
import java.util.Map;

public class ActionStat extends StatBase{

	private MoveStat parent;

	private Map<Integer,TargetStat> targets = new HashMap<>();

	@Override
	public void add(StatItem stat) {
		super.add(stat);
		if (parent != null) {
			parent.add(stat);
		}
	}

	public ActionStat(MoveStat parent) {
		this.parent = parent;
	}

	public ActionStat() {
	}

	public static class TargetStat {
		public int pid;
		public boolean parry;
		public double parryRate;
		public double originDamage;

		public TargetStat(int pid) {
			this.pid = pid;
		}

		public double parryDamage() {
			return originDamage * parryRate;
		}
	}

	public TargetStat getOrBuildTarget(int pid) {
		return targets.computeIfAbsent(pid, t -> new TargetStat(pid));
	}

	public TargetStat getTarget(int pid) {
		return targets.get(pid);
	}

	/**
	 * 是否触发了格挡
	 * @param pid
	 * @return
	 */
	public boolean isParry(int pid) {
		TargetStat stat = getTarget(pid);
		if (stat == null) {
			return false;
		}
		return stat.parry;
	}


}
